package com.seu.algorithms.dp;

/**
 * @author liangfeihu
 * @since 2019/12/3 15:53
 */
public class LongestSequence {

    public static void main(String[] args) {
        final int n = 7;
        int[] nums = {2, 9, 3, 6, 5, 1, 7};
        int sequence = longestSubSequence(nums, n);
        System.out.println(sequence);
    }

    public static int longestSubSequence(int[] nums, int n) {
        int[] lssLengths = new int[n];

        lssLengths[0] = 1;
        for (int i = 1; i < n; i++) {
            int max = 1;
            for (int j = 0; j < i; j++) {
                if (nums[i] > nums[j] && lssLengths[j] >= max) {
                    max = lssLengths[j] + 1;
                }
            }
            lssLengths[i] = max;
        }
        int maxLenth = 1;
        for (int num : lssLengths) {
            System.out.print(num + " ");
            if (num > maxLenth) {
                maxLenth = num;
            }
        }
        System.out.println();
        return maxLenth;
    }

}
